package com.park.platform.service.impl;

import com.park.common.exception.MessageException;
import com.park.common.poo.Config;
import com.park.platform.dao.IBaseDao;
import com.park.platform.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2017-07-02.
 */
@Service
public class ConfigServiceImpl extends BaseService implements IConfigService {

    @Autowired
    private IBaseDao baseDao;

    @Override
    public void saveConfig(Config config){
        baseDao.updateBySql("DELETE FROM config");
        if(config.getFirstLevel().doubleValue() <= 0) throw new MessageException("请输入大于0的一级奖金率");
        if(config.getSecondLevel().doubleValue() <= 0) throw new MessageException("请输入大于0的二级奖金率");
        if(config.getThirdLevel().doubleValue() <= 0) throw new MessageException("请输入大于0的三级奖金率");
        baseDao.save(config, null);
    }

    @Override
    public Config getConfig(){
        return baseDao.queryByHqlFirst("FROM Config ORDER BY id DESC");
    }

}
